package 泛型

object ViewBoundsDemo02 {
  def main(args: Array[String]): Unit = {

    val tom = new Person2("tom", 22)
    val tony = new Person2("tony", 10)

    val value = new CompareComm[Person2](tom, tony)
    println(value.getter.name)

  }

}

class Person2(val name: String, val age: Int) extends Ordered[Person2] {
  override def compare(that: Person2): Int = {
    this.age - that.age
  }

  override def toString: String = this.name + "\t" + this.age
}

class CompareComm[T <% Ordered[T]](obj1: T, obj2: T) {
  def getter = if (obj1 > obj2) obj1 else obj2

  def getter2 = if (obj1.compareTo(obj2) > 0) obj1 else obj2
}